import React, { useState } from "react";
import msgContext from "./msgContext";
import LevelOne from "./LevelOne";
export default function MyFuncComp() {
  const [msg, setMsg] = useState("this is a message!");
  const ref = React.createRef(null);
  function handleClick() {
    setMsg(ref.current.value);
  }
  return (
    <msgContext.Provider value={msg}>
      <div>
        <h1>MyFuncComp</h1>
        {/* 用于修改组件所拥有的msg */}
        <input ref={ref} />
        <button onClick={handleClick}>修改 msg</button>
        <LevelOne msg={msg} />
      </div>
    </msgContext.Provider>
  );
}
